import pymysql

class MysqlInterface:
    def __init__(self, ip, port, usr_name, usr_psword, db):
        self.ip = ip
        self.port = port
        self.usr_name = usr_name
        self.usr_psword = usr_psword
        self.db = db

    def connection(self, sql):
        connection = pymysql.connect(host=self.ip,
                                     port=self.port,
                                     user=self.usr_name,
                                     password=self.usr_psword,
                                     db=self.db,
                                     charset='utf8mb4',
                                     cursorclass=pymysql.cursors.DictCursor)

        try:
            with connection.cursor() as cursor:
                cursor.execute(sql)
                result = cursor.fetchall()

        finally:
            connection.close()

        return result


mysql_interface = MysqlInterface("223.202.209.77", 10000, "ictzxc", "ZXC@ict2016.", "aisdb_suntao")
print(mysql_interface.connection("select 1"))
